Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(formatter): escape double quotes when printing formatter IR #3036

Conversation

dyc3
Copy link
Contributor

@dyc3 dyc3 commented Jun 1, 2024

Summary

Double quotes in source code when printing formatter IR were previously not escaped, causing poor syntax highlighing on the playground. This PR escapes quotes with a simple string replacement.

fixes #1056

Test Plan

CI should pass, but I'm not sure where to add a test for this. I've added a unit test for this.

@github-actions github-actions bot added the A-Formatter Area: formatter label Jun 1, 2024
Copy link

codspeed-hq bot commented Jun 1, 2024

CodSpeed Performance Report

Merging #3036 will not alter performance

Comparing dyc3:06-01-fix_formatter_escape_double_quotes_when_printing_formatter_ir (e352ec5) with main (e3e93cc)

Summary

✅ 90 untouched benchmarks

@dyc3 dyc3 force-pushed the 06-01-fix_formatter_escape_double_quotes_when_printing_formatter_ir branch 2 times, most recently from e10f09e to 5c4e3d0 Compare June 1, 2024 14:20
Copy link
Contributor

@ah-yu ah-yu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI should pass, but I'm not sure where to add a test for this.

Maybe you can refer to this test

fn display_elements() {
let formatted = format!(
SimpleFormatContext::default(),
[format_with(|f| {
write!(
f,
[group(&format_args![
text("("),
soft_block_indent(&format_args![
text("Some longer content"),
space(),
text("That should ultimately break"),
])
])]
)
})]
)
.unwrap();
let document = formatted.into_document();
assert_eq!(
&std::format!("{document}"),
r#"[
group([
"(",
indent([
soft_line_break,
"Some longer content That should ultimately break"
]),
soft_line_break
])
]"#
);
}

@dyc3 dyc3 force-pushed the 06-01-fix_formatter_escape_double_quotes_when_printing_formatter_ir branch from 5c4e3d0 to e352ec5 Compare June 11, 2024 12:31
@dyc3
Copy link
Contributor Author

dyc3 commented Jun 11, 2024

Done. I've added a unit test for this. Thanks for the code pointer @ah-yu

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work @dyc3 !

Copy link
Contributor

@ah-yu ah-yu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Changelog Area: changelog A-Formatter Area: formatter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 Quotes within quotes of Formatter IR isn't escaped
4 participants